home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / xfcn / spttool.cpt / Support Tools eXternals 1.2.5 / card_40319.txt < prev    next >
Text File  |  1990-11-13  |  11KB  |  313 lines

  1. -- card: 40319 from stack: in.5
  2. -- bmap block id: 44867
  3. -- flags: 0000
  4. -- background id: 3858
  5. -- name: SCSIIDToName
  6. ----- HyperTalk script -----
  7. on CloseCard
  8.   put empty into cd fld "ids"
  9.   put empty into cd fld "volumes"
  10.   pass CloseCard
  11. end CloseCard
  12.  
  13. on HideObjects
  14.   hide cd fld "label"
  15.   hide cd fld "volumes"
  16.   hide cd fld "ids"
  17.   hide cd btn "try it!"
  18. end HideObjects
  19.  
  20. on ShowObjects
  21.   show cd fld "label"
  22.   show cd fld "volumes"
  23.   show cd fld "ids"
  24.   show cd btn "try it!"
  25. end ShowObjects
  26.  
  27.  
  28. -- part 2 (field)
  29. -- low flags: 00
  30. -- high flags: 0002
  31. -- rect: left=71 top=147 right=294 bottom=255
  32. -- title width / last selected line: 0
  33. -- icon id / first selected line: 0 / 0
  34. -- text alignment: 0
  35. -- font id: 3
  36. -- text size: 12
  37. -- style flags: 0
  38. -- line height: 16
  39. -- part name: volumes
  40.  
  41.  
  42. -- part 3 (field)
  43. -- low flags: 00
  44. -- high flags: 0002
  45. -- rect: left=19 top=147 right=294 bottom=72
  46. -- title width / last selected line: 0
  47. -- icon id / first selected line: 0 / 0
  48. -- text alignment: 1
  49. -- font id: 3
  50. -- text size: 12
  51. -- style flags: 256
  52. -- line height: 16
  53. -- part name: ids
  54.  
  55.  
  56. -- part 4 (button)
  57. -- low flags: 00
  58. -- high flags: A002
  59. -- rect: left=78 top=302 right=336 bottom=171
  60. -- title width / last selected line: 0
  61. -- icon id / first selected line: 0 / 0
  62. -- text alignment: 1
  63. -- font id: 0
  64. -- text size: 12
  65. -- style flags: 8192
  66. -- line height: 16
  67. -- part name: Try it!
  68. ----- HyperTalk script -----
  69. on mouseUp
  70.   global errGlobal
  71.   put empty into cd fld "ids"
  72.   put empty into cd fld "volumes"
  73.   repeat with driveNdx = 0 to 6
  74.     put SCSIIDToName(driveNdx, "noDialog:errGlobal") into driveName
  75.     if errGlobal Γëá empty then
  76.       answer "Error at ID" && driveNdx & ":" &&errGlobal
  77.       put empty into errGlobal
  78.     else
  79.       put driveNdx into line driveNdx + 1 of cd fld "ids"
  80.       put driveName into line driveNdx + 1 of cd fld "volumes"
  81.     end if
  82.   end repeat
  83. end mouseUp
  84.  
  85.  
  86.  
  87. -- part 5 (field)
  88. -- low flags: 00
  89. -- high flags: 0000
  90. -- rect: left=16 top=129 right=145 bottom=252
  91. -- title width / last selected line: 0
  92. -- icon id / first selected line: 0 / 0
  93. -- text alignment: 0
  94. -- font id: 3
  95. -- text size: 10
  96. -- style flags: 256
  97. -- line height: 13
  98. -- part name: label
  99.  
  100.  
  101. -- part contents for background part 38
  102. ----- text -----
  103. 40/50
  104.  
  105. -- part contents for card part 5
  106. ----- text -----
  107.  SCSI ID   SCSI Drive Name
  108.  
  109. -- part contents for background part 20
  110. ----- text -----
  111.      An XFCN which returns the name of a SCSI drive at a specified SCSI ID.
  112.  
  113.      Calling syntax : SCSIIDToName(SCSI ID#,<ΓÇ£noDialogΓÇ¥:errorGlobal>)
  114.   SCSI ID#: the SCSI ID number (between 0 and 6) to check.  
  115.  
  116. NOTE:  If a drive has been partitioned, then only the name of the first partition will be returned.
  117.  
  118. -- part contents for background part 42
  119. ----- text -----
  120. unit SCSIDToIName;
  121. { SCSIDToIName(diskNumber, ΓÇ£noDialog:ΓÇ¥errorGlobal)                  }
  122. { XFCN returns the name of a SCSI disk given it's ID                }
  123. {}
  124. {   brought to you by:      Anup Murarka             Eric Carlson         }
  125. {                       ALINK:  SKEPTIC           ALINK:  cyNic   }
  126. {                                   CIS:  76004,3356         }
  127. {}
  128. {               We are part of the Support Tools Development Group,     }
  129. {               Apple Computer, Inc.      }
  130. {}
  131. {               please DO NOT contack Mac DTS for support of this code!    }
  132. {}
  133. {               please DO contact the authors for support of this code!     }
  134. {}
  135. {               Send comments, bug reports, requests to any of the above   }
  136. {               E-mail addresses or to:}
  137. {}
  138. {                           (one of us)                  }
  139. {                           Apple Computer, Inc.          }
  140. {                           900 E. Hamilton, Ave.          }
  141. {                           Campbell, CA   95008      }
  142. {                           M/S 72-L                     }
  143. {}
  144. {   Copyright:   ┬⌐ 1989, 1990 by Apple Computer, Inc., all rights reserved.     }
  145. {}
  146. { written by Eric Carlson                                        }
  147. { AppleLink:  cyNic                                              }
  148. { modification history                                                                                        }
  149. {          Date                  Initials                                    Comments                                   }
  150. {          ----              ------          ---------------------------------------------------}
  151. {       1/5/90             ec            first written                                                               }
  152. {       2/26/90           ec            added new "askedForHelp"                                            }
  153. {       4/25/90           ec            fixed bug when passed name of a non SCSI disk                  }
  154. {       5/25/90           ec            modified for A/UX compatibility.  changed name from    }
  155. {                                               ΓÇ£SCSINameΓÇ¥ to ΓÇ£SCSIIDToNameΓÇ¥.  changed version to      }
  156. {                                                1.1}
  157. {}
  158.  
  159. interface
  160.  
  161.     uses
  162.         HyperXCMD;
  163.  
  164.     procedure MAIN (paramPtr: XCmdPtr);
  165.  
  166. implementation
  167.  
  168.     procedure reportToUser (paramPtr: XCmdPtr;
  169.                                     msgStr: str255);
  170. {}
  171. { report something back to the user.  }
  172. { the last parameter (optional) to an external may contain }
  173.  { "noDialog" or "noDialog:GlobalName".  GlobalName is the name }
  174.  { of a HyperTalk global variable into which error messages will be }
  175.  { placed.  we've decided to use this approach to avoid confusing }
  176. { an error message with a valid result being returned from an XFCN. }
  177. {}
  178.         var
  179.             tempStr: str255;
  180.     begin
  181. {check the last param to see if the user requested that}
  182. { we suppress the error dialog }
  183.         ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr);
  184.         UprString(tempStr, true);
  185.         if pos('NODIALOG', tempStr) = 0 then
  186.     { no special error handling specified, throw up a dialog and return the error message }
  187.             begin
  188.                 SendCardMessage(paramPtr, concat('answer "', msgStr, '"'));
  189.                 paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  190.             end
  191.         else if (pos(':', tempStr) > 0) then
  192.     { requested global AND noDialog so we fill in the global and return empty }
  193.             begin
  194.                 tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr));
  195.                                                         { get the name of the HC global  to fill }
  196.                 SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr));
  197.                                                         { and fill it }
  198.                 paramPtr^.returnValue := PasToZero(paramPtr, '');      { return empty }
  199.             end
  200.         else
  201.     { requested noDialog only so we return the error condition as the result }
  202.             paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  203.     end;     { procedure }
  204.  
  205.     function AskedForHelp (paramPtr: XCmdPtr;
  206.                                     syntaxMsg: Str255;
  207.                                     copyrightMsg: Str255): boolean;
  208. {   check to see if the user sent a '?' or a '!' as }
  209. { the only parameter. if so we will respond with }
  210. { the calling syntax or the copyright/version info }
  211. { for this external }
  212. {}
  213.         var
  214.             firstStr: str255;
  215.     begin
  216.         askedForHelp := false;
  217.         if paramPtr^.paramCount = 1 then
  218.             begin
  219.                 ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr);
  220.                     { what is the first param? }
  221.                 if firstStr = '?' then
  222.                     begin
  223.                         reportToUser(paramPtr, syntaxMsg);
  224.                         askedForHelp := true
  225.                     end  { asked for help }
  226.                 else if firstStr = '!' then
  227.                     begin
  228.                         reportToUser(paramPtr, copyRightMsg);
  229.                         askedForHelp := true
  230.                     end;     { asked for copyright info }
  231.             end;     { one parameter passed }
  232.     end;     { function }
  233.  
  234.     function LongToString (paramPtr: XCmdPtr;
  235.                                     num: LONGINT): Str255;
  236. { why, oh why did dan write this one as a procedure??? }
  237.         var
  238.             tempStr: str255;
  239.     begin
  240.         LongToStr(paramPtr, num, tempStr);
  241.         LongToString := tempStr;
  242.     end;
  243.  
  244.     function BitTest (AddressToCheck: ptr;
  245.                                     TotalBits: integer;
  246.                                     BitToTest: longint): boolean;
  247.     { function that allows caller to use std. 68000 bit notation instead of the Toolbox's reversed notation}
  248.     { example:  bit 0 (the least significant bit) in a byte is bit 7 in the Toolbox's notation}
  249.     begin
  250.         BitTest := BitTst(AddressToCheck, TotalBits - 1 - BitToTest);
  251.     end;
  252.  
  253.     function AUXisRunning: boolean;
  254.         const
  255.             HWCfgFlag = $0B22;
  256.     begin
  257.         AUXisRunning := BitTest(pointer(HWCfgFlag), 16, 9);
  258.     end;
  259.  
  260.     procedure SCSIName (paramPtr: XCmdPtr);
  261.         { the BITNOT of a driver's ref num is it's number in the unit table.  in the case of a driver for a SCSI disk the entry }
  262.         var
  263.             tempStr, volName: str255;
  264.             requestedSCSIID: integer;
  265.             PB: HParamBlockRec;
  266.             volInfoErr: OSErr;
  267.             done: boolean;
  268.     begin
  269.         if askedForHelp(paramPtr, 'SCSIIDToName(SCSI ID#,<ΓÇ£noDialogΓÇ¥:errorGlobal>)', '┬⌐ 1989 Apple Computer, Inc. v.1.1,  bu Eric Carlson.') then
  270.             exit(SCSIName);
  271.         if paramPtr^.paramCount < 1 then                    { we need the disk name to search for }
  272.             begin
  273.                 reportToUser(paramPtr, 'SCSI ID expected');
  274.                 exit(SCSIName)
  275.             end;
  276.  
  277.         ZeroToPas(paramPtr, paramPtr^.params[1]^, tempStr);
  278.         requestedSCSIID := StrToNum(paramPtr, tempStr);
  279.         if (requestedSCSIID < 0) or (requestedSCSIID > 6) then        { an illegal SCSI ID# }
  280.             begin
  281.                 reportToUser(paramPtr, 'SCSI ID must be > 0 and < 7.');
  282.                 exit(SCSIName)
  283.             end;
  284.  
  285.         zeroBytes(paramPtr, @PB, sizeOf(PB));             { start out with a clean paramblock }
  286.         PB.ioNamePtr := @volName;
  287.         PB.ioVolIndex := 0;
  288.         done := false;
  289.         repeat
  290.             PB.ioVolIndex := PB.ioVolIndex + 1;               { next volume }
  291.             volInfoErr := PBHGetVInfo(@PB, false);             { get the next volume name }
  292.             if volInfoErr = noErr then                       { see if we're done yet }
  293.                 if BITNOT(PB.ioVDRefNum) - 32 = requestedSCSIID then
  294.                     done := true;
  295. { the trick here is that the BITNOT of a drive's ioVDRefNum is equal to its number in the unit table, }
  296. {  which is it's SCSI id + 32 }
  297.         until (volInfoErr <> noErr) or (done);
  298.  
  299.         if volInfoErr <> noErr then                          { return empty if no disk mounted }
  300.             volName := ''
  301.         else
  302.             volName := concat(volName, ':');
  303.  
  304.         paramPtr^.returnValue := PasToZero(paramPtr, volName);             { return the drive name }
  305.  
  306.     end;         { procedure SCSIName}
  307.  
  308.     procedure MAIN (paramPtr: XCmdPtr);
  309.     begin
  310.         SCSIName(paramPtr);
  311.     end;
  312.  
  313. end.     { unit SCSIName}